// Open Credit System
// UVa ID: 11078
// Verdict: Accepted
// Submission Date: 2017-11-07
// UVa Run Time: 0.050s
//
// 版权所有（C）2017，邱秋。metaphysis # yeah dot net

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int cases, n, score;
    
    cin >> cases;
    for (int c = 1; c <= cases; c++)
    {
        cin >> n;
        
        int inf = -200000, diff = -400000;
        for (int i = 0; i < n; i++)
        {
            cin >> score;
            
            if (i) diff = max(diff, inf - score);
            
            inf = max(inf, score);
        }
        
        cout << diff << '\n';
    }

    return 0;
}
